@extends('admin.layouts.base')

@section('title','控制面板')

@section('pageHeader','控制面板')

@section('pageDesc','DashBoard')

@section('content')

    
    <div class="row page-title-row" style="margin:5px;">
        <div class="col-md-6">
			<!--<a href="/admin/wechat/leading/0" class="btn btn-default btn-md">
                <i class="fa fa-file-excel-o"></i> 批量导入
            </a>&nbsp;&nbsp;-->
			<!-- Single button -->
			<div class="btn-group">
			  <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
				分组 <span class="caret" style="vertical-align:middle;"></span>
			  </button>
			  <ul class="dropdown-menu">
				<li @if($gid==-1)class="disabled"@endif><a href="/admin/wechat">全部</a></li>
				<li @if($gid==0)class="disabled"@endif><a href="/admin/wechat/0">无分组</a></li>
				@foreach($wechatgroup as $v)
				 <li @if($gid==$v['id'])class="disabled"@endif><a href="/admin/wechat/{{$v['id']}}">{{$v['name']}}</a></li>
			    @endforeach
				
				
			  </ul>
			</div>
        </div>
        <div class="col-md-6 text-right">
		@if($role->role_id!=1)
			<a href="javascript:;" class="btn btn-default btn-md cogs-update">
                <i class="fa fa-cogs"></i> 批量修改
            </a>
			<a href="javascript:;" onclick="batchDel()" class="btn btn-danger btn-md" style="">
                <i class="fa fa-minus-circle"></i> 批量删除
            </a>
			<a href="/admin/wechat/create" class="btn btn-success btn-md">
                <i class="fa fa-plus-circle"></i> 添加微信
            </a>
		@endif
        </div>
    </div>

    <div class="row">
        <div class="col-xs-12">
            <div class="box">

                @include('admin.partials.errors')
                @include('admin.partials.success')
                <div class="box-body">
                    <table id="tags-table" class="table table-bordered table-hover">
                        <thead>
                        <tr>
                            <th data-sortable="false" class="hidden-sm ">@if($role->role_id!=1)<input id="all" type="checkbox"/>全选@endif</th>
                            <!--<th class="hidden-sm">所属用户</th>-->
                            <th class="hidden-sm">微信号</th>
							<th class="hidden-sm">微信昵称</th>
							<th class="hidden-sm">手机号</th>
                            <th class="hidden-md">随机数</th>
							{{--<th class="hidden-md">调用值</th>--}}
                            <th class="hidden-md">状态</th>
                            <th class="hidden-md">客服时间</th>
                            <th class="hidden-md">分组<i style='color:#999;'>(推广员)</i></th>
                            <th data-sortable="false">操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
    </div>
    </div>
    <div class="modal fade" id="modal-delete" tabIndex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        ×
                    </button>
                    <h4 class="modal-title">提示</h4>
                </div>
                <div class="modal-body">
                    <p class="lead">
                        <i class="fa fa-question-circle fa-lg"></i>
                        确认要删除这个微信吗?
                    </p>
                </div>
                <div class="modal-footer">
                    <form class="deleteForm" method="POST" action="/admin/wechat/recover">
                        <input type="hidden" name="_token" value="{{ csrf_token() }}">
                        <input type="hidden" name="_method" value="DELETE">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="submit" class="btn btn-danger">
                            <i class="fa fa-times-circle"></i>确认
                        </button>
                    </form>
                </div>

            </div>
        </div>
    </div>

	{{--回收微信--}}
    <div class="modal fade" id="modal-hs" tabIndex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        ×
                    </button>
                    <h4 class="modal-title">提示</h4>
                </div>
                <div class="modal-body">
                    <p class="lead">
                        <i class="fa fa-question-circle fa-lg"></i>
                        确认要申请回收这个微信吗?
                    </p>
                </div>
                <div class="modal-footer">
                    <form class="hsForm" method="POST" action="/admin/wechat/recover">
                        <input type="hidden" name="_token" value="{{ csrf_token() }}">
                        <input type="hidden" name="_method" value="POST">
						<input type="hidden" name="type" value="recover">
						<input type="hidden" name="id" value="">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="submit" class="btn btn-danger">
                            <i class="fa fa-times-circle"></i>确认
                        </button>
                    </form>
                </div>

            </div>
        </div>
    </div>
	{{--取消申请--}}
    <div class="modal fade" id="modal-qq" tabIndex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        ×
                    </button>
                    <h4 class="modal-title">提示</h4>
                </div>
                <div class="modal-body">
                    <p class="lead">
                        <i class="fa fa-question-circle fa-lg"></i>
                        确认要取消这个申请吗?
                    </p>
                </div>
                <div class="modal-footer">
                    <form class="qqForm" method="POST" action="/admin/wechat/recover">
                        <input type="hidden" name="_token" value="{{ csrf_token() }}">
                        <input type="hidden" name="_method" value="POST">
						<input type="hidden" name="type" value="stop">
						<input type="hidden" name="id" value="">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="submit" class="btn btn-danger">
                            <i class="fa fa-times-circle"></i>确认
                        </button>
                    </form>
                </div>

            </div>
        </div>
    </div>
	
    {{--批量删除--}}
    <div class="modal fade" id="modal-batch-del" tabIndex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        ×
                    </button>
                    <h4 class="modal-title">提示</h4>
                </div>
                <div class="modal-body">
                    <p class="lead">
                        <i class="fa fa-question-circle fa-lg"></i>
                        确认要删除这些微信吗?
                    </p>
                </div>
                <div class="modal-footer">
                    <form class="batchDelForm" method="POST" action="/admin/wechat">
                        <input type="hidden" name="_token" value="{{ csrf_token() }}">
                        <input type="hidden" name="_method" value="DELETE">
                        <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                        <button type="submit" class="btn btn-danger">
                            <i class="fa fa-times-circle"></i>确认
                        </button>
                    </form>
                </div>

            </div>
        </div>
    </div>
	
	{{--批量修改--}}
    <div class="modal fade" id="modal-cogs-update" tabIndex="-1">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">
                        ×
                    </button>
                    <h4 class="modal-title">批量修改(<span style="color:red;">温馨提示：留空则不做修改。</span>)</h4>
                </div>
                <div class="modal-body">
                    <form class="batchCogsForm form-horizontal" method="POST" onsubmit="return setUpdateId();" action="/admin/wechat/cogsUpdate">
                        <input type="hidden" name="_token" value="{{ csrf_token() }}">
                        <input type="hidden" name="update_id" value=""/>
						<div class="form-group">
							<label for="tagMax_rand" class="col-md-2 control-label">随机值</label>
							<div class="col-md-9">
								<input class="form-control" type="number" name="max_rand" value="" placeholder="随机数"/>
							</div>
						</div>
						<div class="form-group">
							<label for="tagStatus" class="col-md-2 control-label">状态</label>
							<div class="col-md-9">
								<select class="form-control" name="status" id="tagStatus">
									<option value="-1">不修改</option>
									<option value="0">禁用</option>
									<option value="1">正常</option>
									<option value="2">暂封</option>
									<option value="3">永封</option>
								</select>
							</div>
						</div>
						<div class="form-group">
							<label for="tagOnline_time tagOffline_time" class="col-md-2 control-label">在线时间</label>
							<div class="col-md-9">
								<input type="time" style="width:44.44444444%;" class="form-control col-md-4" name="online_time" value=""/>
								<span style="float:left;margin-left:4.225%;margin-right:4.225%;">—</span>
								<input type="time" style="width:44.44444444%;" class="form-control col-md-4" name="offline_time" value=""/>
							</div>
						</div>
						<div class="form-group">
							<label for="tagGroup" class="col-md-2 control-label">分组</label>
							<div class="col-md-9">
								<select class="form-control" name="group" id="tagGroup">
								<option value="-1" >请选择分组</option>
									<option value="0" >无分组</option>
								  @foreach($wechatgroup as $v)
									<option value="{{$v['id']}}" >{{$v['name']}}</option>
								   @endforeach
								</select>
							</div>
						</div>
                    </form>
                </div>
                <div class="modal-footer">
                    
                        <button type="button" class="btn btn-default" data-dismiss="modal">
							<i class="fa fa-times-circle"></i>  取消</button>
                        <button type="button" class="btn btn-success" onclick="$('.batchCogsForm').submit();">
                            <i class="fa fa-check-circle"></i>  确认
                        </button>
                </div>

            </div>
        </div>
    </div>
@stop

@section('js')
    <script>
        $(function () {
            var table = $("#tags-table").DataTable({
                language: {
                    "sProcessing": "处理中...",
                    "sLengthMenu": "显示 _MENU_ 项结果",
                    "sZeroRecords": "没有匹配结果",
                    "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
                    "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
                    "sInfoFiltered": "(由 _MAX_ 项结果过滤)",
                    "sInfoPostFix": "",
                    "sSearch": "搜索:",
                    "sUrl": "",
                    "sEmptyTable": "表中数据为空",
                    "sLoadingRecords": "载入中...",
                    "sInfoThousands": ",",
                    "oPaginate": {
                        "sFirst": "首页",
                        "sPrevious": "上页",
                        "sNext": "下页",
                        "sLast": "末页"
                    },
                    "oAria": {
                        "sSortAscending": ": 以升序排列此列",
                        "sSortDescending": ": 以降序排列此列"
                    }
                },
                order: [[2, "desc"]],
                serverSide: true,
                ajax: {
                    url: '/admin/wechat/index',
                    type: 'POST',
					data: function (d) {
						d.gid = {{$gid}};
					},
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                    }
                },
                "columns": [
                    {"data": "id"},
                    /* {"data": "username"}, */
                    {"data": "wx_num"},
					{"data": "wx_nike"},
					{"data": "phone"},
                    {"data": "max_rand"},
					/*{"data": "id",render:function(data,type,row){ return "<a href='/admin/wechatvalue/"+row['id']+"/index'>查看</a>";}},*/
                    {"data": "status",render:function(data){
						switch(data){
							case 0: return "<span style='color:black;'>禁用</span>";
							case 1: return "<span style='color:green;'>正常</span>";
							case 2: return "<span style='color:#fa4358;'>暂封</span>";
							case 3: return "<span style='color:#ff0105;'>永封</span>";
						}
					}},
                    {"data": "online_time",render:function(data,type,row){ return data+'—'+row['offline_time'];}},
                    {"data": "name",render:function(data,type,row){if(data==null){return "<i>无分组</i>"}else{return data+"<i style='color:#999;'>("+row['username']+")</i>";}}},
                    {"data": "action"}
                ],
                columnDefs: [
                    {
                        'targets': -1, "render": function (data, type, row)
                        {
							var caozuo = '';
							@if($role->role_id!=1)
								@if($role->role_id<8)
									caozuo += "<a href='/admin/wechatvalue/"+row['id']+"/index' class='X-Small btn-xs text-info'> <i class='fa fa-key'></i> 调用值</a>";
								@endif
								caozuo += '<a style="margin:3px;" href="/admin/wechat/' + row['id'] + '/edit" class="X-Small btn-xs text-success "><i class="fa fa-edit"></i> 编辑</a>';
								caozuo += '<a style="margin:3px;" href="#" attr="' + row['id'] + '" class="delBtn X-Small btn-xs text-danger "><i class="fa fa-times-circle-o"></i> 删除</a>';
                            @endif
							@if($role->role_id==7||$role->role_id==8)
								if(row['name']!=null){
									if(row['recover']==0){
										caozuo +='<a style="margin:3px;" href="#" attr="' + row['id'] + '" class="hsBtn X-Small btn-xs text-info "><i class="fa fa-recycle"></i> 申请回收</a>';
									}else{
										caozuo +='<a style="margin:3px;" href="#" attr="' + row['id'] + '" class="qqBtn X-Small btn-xs text-danger "><i class="fa fa-stop"></i> 取消申请</a>';
									}
								}		
							@endif
						   return caozuo;
                        }
                    },
                    {
                        'targets': 0, "render": function (data, type, row)
                        {
							 var caozuoCB = '';
							@if($role->role_id!=1)
								caozuoCB += '<div class="checkbox hidden-sm"><label><input class="itemCB" name="itemCB[]" type="checkbox" value="' + row['id'] + '"></label></div>';
							@endif
                            return caozuoCB;
                        }
                    }
                ]
            });

            table.on('preXhr.dt', function () {
                loadShow();
            });

            table.on('draw.dt', function () {
                loadFadeOut();
            });

            table.on('order.dt search.dt', function () {
                table.column(0, {search: 'applied', order: 'applied'}).nodes().each(function (cell, i) {
                    cell.innerHTML += (i + 1);
                });
            }).draw();

            $("table").delegate('.delBtn', 'click', function () {
                var id = $(this).attr('attr');
                $('.deleteForm').attr('action', '/admin/wechat/' + id);
                $("#modal-delete").modal();
            });
			$("table").delegate('.hsBtn', 'click', function () {
                var id = $(this).attr('attr');
                //$('.hsForm').attr('action', '/admin/wechat/' + id);
				$('input[name=id]').val(id);
                $("#modal-hs").modal();
            });
			$("table").delegate('.qqBtn', 'click', function () {
                var id = $(this).attr('attr');
                //$('.qqForm').attr('action', '/admin/wechat/' + id);
				$('input[name=id]').val(id);
                $("#modal-qq").modal();
            });
			$(".cogs-update").click(function(){
				$("#modal-cogs-update").modal();
			});
        });
		function setUpdateId(){
			var valArr = new Array;
			$(".itemCB").each(function (i) {
				if (this.checked) {
					valArr.push($(this).val());
				}
			});
			var ids = valArr.join(',');
			$("input[name=update_id]").val(ids);
			if($("input[name=update_id]").val()==''){
				alert("请选择需要修改的选项！");
				return false;
			}
			return true;
		}
    </script>

@stop